package Facade;

import java.util.Collection;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import Entity.Society;

/**
 * Session Bean implementation class SocietyFacade
 */
@Stateless
public class SocietyFacade implements SocietyFacadeRemote {

	@PersistenceContext(unitName = "POLEINFODB")
	protected EntityManager entityMgr;

	public Society addSociety(Society s) {
		entityMgr.persist(s);
		return s;
	}

	public void clearAllSocieties() {
		Collection<Society> Societies = listSocieties();
		for(Society nextSociety : Societies){
			entityMgr.remove(nextSociety);
		}
	}

	public void clearSociety(int id_society) {
		Society s =entityMgr.find(Society.class, id_society);
		entityMgr.remove(s);
	}

	@SuppressWarnings("unchecked")
	public Collection<Society> listSocieties() {
		
		return entityMgr.createQuery("SELECT s FROM Society as s").getResultList();
		
	}



}
